--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_1
       log:  /Users/michael/Documents/git_repos/maptile_geo_templates/build/build_cz1990.log
  log type:  text
 opened on:  29 Jul 2017, 23:57:59

. *! 29jul2017  Michael Stepner, stepner@mit.edu
. 
. * merges 1990 County shapefile into a 1990 CZ shapefile
. 
. /*******************************
> 
> ** INPUT FILES ** 
> - cw_cty_czone.dta
>         Provided by David Dorn at http://www.ddorn.net/data.htm -- file [E6]
>         
>         Original citation:
>                 David Autor and David Dorn. "The Growth of Low Skill Service Jobs
>                 and the Polarization of the U.S. Labor Market." American Economic
>                 Review, 103(5), 1553-1597, 2013.
> 
> *******************************/
. 
. *** Step 0: Initialize
. 
. * Check if run using -project-
. return clear

. capture project, doinfo

. if (_rc==0 & !mi(r(pname))) global root `r(pdir)'  // run using -project-

. else {  // running directly
. 
.         global root "/Users/michael/Documents/git_repos/maptile_geo_templates/build"
. 
.         * Disable project (since running do-files directly)
.         cap program drop project
.         program define project
.                 di "Project is disabled, skipping project command. (To re-enable, run -{stata program drop project}-)"
.         end
.         
. }

. 
. * Specify subdirectories
. global raw "$root/raw_data/cz1990"

. global out "$root/geo_templates/cz1990"

. global test "$root/tests/cz1990"

. 
. * Add utility programs to path
. adopath ++ "$root/util"
  [1]              "/Users/michael/Documents/git_repos/maptile_geo_templates/build/util"
  [2]  (UPDATES)   "/Applications/Stata/ado/updates/"
  [3]  (BASE)      "/Applications/Stata/ado/base/"
  [4]  (SITE)      "/Applications/Stata/ado/site/"
  [5]              "."
  [6]  (PERSONAL)  "~/Library/Application Support/Stata/ado/personal/"
  [7]  (PLUS)      "~/Library/Application Support/Stata/ado/plus/"
  [8]  (OLDPLACE)  "~/ado/"

. 
. * Tell -project- that we use -save12-
. project, original("$root/util/save12.ado")
project build_cz1990 > do-file uses original: "util/save12.ado" filesig(2718885224:622)

. 
. * Tell -project- that we use -mergepoly- (obtained from SSC)
. project, original("$root/util/mergepoly.ado")
project build_cz1990 > do-file uses original: "util/mergepoly.ado" filesig(2147366178:9474)

. project, original("$root/util/mergepoly.hlp")
project build_cz1990 > do-file uses original: "util/mergepoly.hlp" filesig(2852734305:7068)

. 
. 
. *** Step 1: Use Dorn County -> CZ crosswalk to merge CZ variable onto county database
. project, original("$raw/cw_cty_czone.dta")
project build_cz1990 > do-file uses original: "raw_data/cz1990/cw_cty_czone.dta" filesig(224482024:51020)

. use "$raw/cw_cty_czone.dta", clear

. rename cty_fips county

. rename czone cz

. keep county cz

. 
. project, original("$root/geo_templates/county1990/county1990_database.dta") preserve
project build_cz1990 > do-file uses original: "geo_templates/county1990/county1990_database.dta" filesig(2555161201:24166)

. merge 1:m county using "$root/geo_templates/county1990/county1990_database.dta", assert(3) nogen
(note: variable county was float, now double to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                             3,323  
    -----------------------------------------

. compress
  variable county was double now long
  (13,292 bytes saved)

. 
. 
. *** Step 2: Merge county polygons into CZs
. 
. project, original("$root/geo_templates/county1990/county1990_coords.dta") preserve
project build_cz1990 > do-file uses original: "geo_templates/county1990/county1990_coords.dta" filesig(2233363090:4929959)

. mergepoly id using "$root/geo_templates/county1990/county1990_coords.dta", ///
>         coordinates("$out/cz1990_coords.dta") ///
>         by(cz) replace
Looping over 741 by-groups:
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400
..................................................   450
..................................................   500
..................................................   550
..................................................   600
..................................................   650
..................................................   700
.........................................
. save12 "$out/cz1990_database.dta", replace
(saving in Stata 12 format, which can be read by Stata 11 or 12)
file /Users/michael/Documents/git_repos/maptile_geo_templates/build/geo_templates/cz1990/cz1990_database.dta saved

. project, creates("$out/cz1990_database.dta")
project build_cz1990 > do-file creates: "geo_templates/cz1990/cz1990_database.dta" filesig(3477152381:4960)

. 
. * Resave coords in Stata 12 format
. use "$out/cz1990_coords.dta", clear

. save12 "$out/cz1990_coords.dta", replace
(saving in Stata 12 format, which can be read by Stata 11 or 12)
file /Users/michael/Documents/git_repos/maptile_geo_templates/build/geo_templates/cz1990/cz1990_coords.dta saved

. project, creates("$out/cz1990_coords.dta")
project build_cz1990 > do-file creates: "geo_templates/cz1990/cz1990_coords.dta" filesig(3785510865:2974553)

. 
. 
. *** Reference other files using -project-
. project, relies_on("$root/readme.txt")
project build_cz1990 > do-file relies on: "readme.txt" filesig(2581144236:573)

. project, relies_on("$out/cz1990_maptile.ado")
project build_cz1990 > do-file relies on: "geo_templates/cz1990/cz1990_maptile.ado" filesig(1243727699:2685)

. project, relies_on("$out/cz1990_maptile.md")
project build_cz1990 > do-file relies on: "geo_templates/cz1990/cz1990_maptile.md" filesig(1350986421:1040)

. project, relies_on("$out/cz1990_maptile.smcl")
project build_cz1990 > do-file relies on: "geo_templates/cz1990/cz1990_maptile.smcl" filesig(1126376166:1188)

. 
. *** Test geo-specific options
. use "$out/cz1990_database.dta", clear

. rename id test

. 
. maptile test, geo(cz1990) geofolder($out) ///
>         savegraph("$test/cz1990_noopt.png") resolution(0.25) replace
(file /Users/michael/Documents/git_repos/maptile_geo_templates/build/tests/cz1990/cz1990_noopt.png written in PNG format)

. project, creates("$test/cz1990_noopt.png") preserve
project build_cz1990 > do-file creates: "tests/cz1990/cz1990_noopt.png" filesig(962422374:431613)

.         
. maptile test, geo(cz1990) geofolder($out) ///
>         conus ///
>         savegraph("$test/cz1990_conus.png") resolution(0.25) replace
(file /Users/michael/Documents/git_repos/maptile_geo_templates/build/tests/cz1990/cz1990_conus.png written in PNG format)

. project, creates("$test/cz1990_conus.png") preserve
project build_cz1990 > do-file creates: "tests/cz1990/cz1990_conus.png" filesig(2936478532:411510)

. 
. project, original("$root/geo_templates/state/state_coords_clean.dta") preserve
project build_cz1990 > do-file uses original: "geo_templates/state/state_coords_clean.dta" filesig(2969291408:868121)

. copy "$root/geo_templates/state/state_coords_clean.dta" "$out/state_coords_clean.dta"

. 
. maptile test, geo(cz1990) geofolder($out) ///
>         stateoutline(medium) ///
>         savegraph("$test/cz1990_stoutline.png") resolution(0.25) replace
(file /Users/michael/Documents/git_repos/maptile_geo_templates/build/tests/cz1990/cz1990_stoutline.png written in PNG format)

. project, creates("$test/cz1990_stoutline.png") preserve
project build_cz1990 > do-file creates: "tests/cz1990/cz1990_stoutline.png" filesig(114080733:451793)

. 
. maptile test, geo(cz1990) geofolder($out) ///
>         conus stateoutline(medium) ///
>         savegraph("$test/cz1990_conus_stoutline.png") resolution(0.25) replace
(file /Users/michael/Documents/git_repos/maptile_geo_templates/build/tests/cz1990/cz1990_conus_stoutline.png written in PNG format)

. project, creates("$test/cz1990_conus_stoutline.png") preserve
project build_cz1990 > do-file creates: "tests/cz1990/cz1990_conus_stoutline.png" filesig(72232346:427384)

. 
. erase "$out/state_coords_clean.dta"

. 
end of do-file
      name:  plog_1
       log:  /Users/michael/Documents/git_repos/maptile_geo_templates/build/build_cz1990.log
  log type:  text
 closed on:  29 Jul 2017, 23:58:52
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
